# 面向对象
# 面向对象概述
# 基于面向过程编程的问题分析
# 基于面向对象编程的问题分析
# 面向对象的基本概念
# 对象
# 类
# 抽象
# 封装
# 继承
# 多态
# 类与对象
# 类与对象的关系
# 类的定义

class Car:
    wheels = 4
    def drive(self):
        print('开车方式')
    def stop(self):
        print('停车方式')


# 对象的创建与使用
# 对象的创建
my_car= Car()


# 访问对象成员
print(my_car.wheels)
my_car.drive()
my_car.stop()


# 访问限制
# class PersonInfo:
#     __weight = 55
#     def __info(self):
#         print('我的体重是90kg')

# 使用私有成员

# person.__info()

#
# class PersonInfo:
#     ...
#     def get_weight(self):
#         print(f'我的体重是{self.__weight}kg')
#
# person.get_weight()


class PersonInfo:
    __weight = 200
    def __info(self):
        print(f'我的体重是{self.__weight}kg')
    def get_weight(self):
        print(f'我的体重是{self.__weight}kg')
        self.__info()
person = PersonInfo()
person.get_weight()



# 构造方法
class Person:
    def __init__(self,name,sex):
        self.name = name
        self.sex = sex
    def introduce(self):
        print(f'姓名：{self.name}')
        print(f'性别：{self.sex}')
person_one = Person('黄楠','男')
person_one.introduce()
person_tow = Person('黄柳','女')
person_tow.introduce()



# 类方法和静态方法
# 类方法
# 定义类方法
class Test:
    @classmethod
    def use_classmet(cls):
        print("我是类方法")

# 调用类方法
test = Test()
test.use_classmet()
Test.use_classmet()

# 修改类属性
class aaa:
    count = 0
    @classmethod
    def add_two(cls):
        cls.count = 2
print(aaa.count)
aaa.add_two()
print(aaa.count)

# 静态方法
class Example:
    num = 10
    @staticmethod
    def static_method():
        print(f"类属性的值为：{Example.num}")
        print("---静态方案")
example = Example()
example.static_method()
Example.static_method()



# 继承
# 单继承
class Amphibian:
    name = "猜猜我是谁，喜欢吃好吃的"
    def features(self):
        print("喜欢睡觉")
        print("喜欢爬山")
class Frog(Amphibian):
    def attr(self):
        print("是黄楠!")
frog = Frog()
print(frog.name)
frog.features()
frog.attr()




# 多继承
class English:
    def receive_eng_kow(self):
        print('具备英语知识')
class Math:
    def receive_math_kow(self):
        print('具备数学知识')
class Student(English,Math):
    def study(self):
        print('学生要多看看世界')
stu = Student()
stu.receive_eng_kow()
stu.receive_math_kow()
stu.study()


# 方法的重写
class Felines:
    def speciality(self):
        print("猫科动物善于奔跑")
class Cat(Felines):
    name = "猫"
    def speciality(self):
        print(f'{self.name}爱吃鱼')
        print(f'{self.name}会爬树')
cat = Cat()
cat.speciality()


# super（）函数
class Cat(Felines):
    name = "猫"
    def speciality(self):
        print(f'{self.name}爱吃鱼')
        print(f'{self.name}会爬树')
        print('-'*20)
        super().speciality()
cat = Cat()
cat.speciality()


# 多态
class Animal(object):
    def move(self):
        pass
class Rabbit(Animal):
    def move(self):
        print("我们这么久没见")
class Snail(Animal):
    def move(self):
        print("却没人敢聊重点")
def text(obj):
    obj.move()
rabbit = Rabbit()
text(rabbit)
snail = Snail()
text(snail)




